package com.gzu.ltms.controller.user;


import com.gzu.ltms.aspect.ApiOperationLog;
import com.gzu.ltms.entity.dto.FindUserByIdReqDTO;
import com.gzu.ltms.entity.dto.FindUserByIdRspDTO;
import com.gzu.ltms.entity.vo.UpdateReqVO;
import com.gzu.ltms.entity.vo.UserLoginReqVO;
import com.gzu.ltms.response.Response;
import com.gzu.ltms.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(name = "用户相关接口")
public class UserController {

    @Resource
    private UserService userService;


    @PostMapping("/login")
    @ApiOperationLog(description = "用户登录")
    @Operation(summary = "用户登录")
    public Response<String> loginAndRegister(@Validated @RequestBody UserLoginReqVO userLoginReqVO) {
        return userService.loginAndRegister(userLoginReqVO);
    }

    @PostMapping("/logout")
    @ApiOperationLog(description = "用户登出")
    @Operation(summary = "用户登出")
    public Response<String> logout() {
        return userService.logout();
    }

    @PutMapping("/password/update")
    @ApiOperationLog(description = "修改密码")
    @Operation(summary = "修改密码")
    public Response<String> update(@Validated @RequestBody UpdateReqVO updateReqVO) {
        return userService.update(updateReqVO);
    }

    @GetMapping("/findById")
    @ApiOperationLog(description = "根据id查询用户")
    @Operation(summary = "根据id查询用户")
    public Response<FindUserByIdRspDTO> findById(@Validated @RequestBody FindUserByIdReqDTO findUserByIdReqDTO) {
        return userService.findById(findUserByIdReqDTO);
    }

}
